package com.itheima.test02;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/*
TCP 的服务端 代码
接受客户端传来的 消息
同时给 客户端反馈

 */
public class ServerDemo {

    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(9999);
        Socket socket = ss.accept();
        InputStream is = socket.getInputStream();
        int b;
        while ((b=is.read())!=-1){
            System.out.println((char)b);
        }
        //给客户端一个响应
        OutputStream os = socket.getOutputStream();
        os.write("hi".getBytes());
        //告诉 客户端 数据传输完毕了
        socket.shutdownOutput();
        //os.close();
        ss.close();

    }
}
